package view;

import java.awt.Component;
import java.net.URL;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

public class ComboBoxRenderer extends JLabel implements ListCellRenderer {

	private static final long serialVersionUID = 1L;

	public ComboBoxRenderer() {
		setOpaque(true);
		setHorizontalAlignment(CENTER);
		setVerticalAlignment(CENTER);
	}

	public Component getListCellRendererComponent(JList list, Object value,
			int index, boolean isSelected, boolean cellHasFocus) {

		String selectedIndex = value.toString();

		if (isSelected) {
			setBackground(list.getSelectionBackground());
			setForeground(list.getSelectionForeground());
		} else {
			setBackground(list.getBackground());
			setForeground(list.getForeground());
		}

		URL ordnerURL  =  getClass().getResource("/images/ordner.png");
		ImageIcon icon = new ImageIcon(ordnerURL);

		setIcon(icon);
		if (icon != null) {
			setText(selectedIndex);
			setFont(list.getFont());
		}

		return this;
	}
}